package homework.day11;

import java.util.ArrayList;

import java.util.Iterator;
import java.util.List;

public class BookDaoImpl implements IBookDao {

    private         List<Book> books = new ArrayList<>();
    public BookDaoImpl(){
        //模擬一些书籍的數據
        Book b1 = new Book(1,"renjian","mhx",45.6);
        Book  b2 = new Book (2, "ert","jack",56.7);
        Book  b3 = new Book (3, "wer","success",34.5);
        books.add(b1);
        books.add(b2);
        books.add(b3);
    }



    public void save(Book b) {
        books.add(b);
    }


    public List<Book> findAll() {
        return books;
    }


    public void delById( Integer id) {
        for (int i = 0; i <books.size(); i++) {
            if(books.get(i).getId()==id) {
                books.remove(books.get(i));
                return;
            }
        }
    }


    public void delByPrice(double price) {
        for (int i = 0; i < books.size(); i++) {
            if(books.get(i).getPrice()>price) {
                books.remove(books.get(i));
                break;
            }
        }

    }
}
